package com.cos.hospital.model.retrofit;

import com.cos.hospital.tool.ULog;
import com.cos.hospital.tool.UTxt;
import com.cos.hospital.widget.ProgressDialog;
import com.google.gson.Gson;

import io.reactivex.Observer;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;

/**
 * Created by yby on 2017/6/23
 */
public class MyObserver<T> implements Observer<T> {
    private String describe;

    public MyObserver() {
    }

    public MyObserver(String describe) {
        this.describe = describe;
    }

    @Override
    public void onSubscribe(@NonNull Disposable d) {
//        ULog.commonV("onSubscribe:");
    }

    @Override
    public void onNext(@NonNull T t) {
        if (!UTxt.isEmpty(describe)) {
            ULog.commonD(describe + "-->" + new Gson().toJson(t));
        }
    }

    @Override
    public void onError(@NonNull Throwable e) {
        ProgressDialog.getInstance().stopProgressDialog();
        ULog.commonE(describe + "-->" + e.toString());
    }

    @Override
    public void onComplete() {
//        ULog.commonD("onComplete:");
        ProgressDialog.getInstance().stopProgressDialog();
    }
}
